package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.QgPayBusiness;
import com.ruoyi.web.service.IQgPayBusinessService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * QGPay业务Controller
 *
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/qg-pay/business")
@AllArgsConstructor
public class QgPayBusinessController extends BaseController {
    private IQgPayBusinessService qgPayBusinessService;

    /**
     * 查询QGPay业务列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:business:list')")
    @GetMapping("/list")
    public TableDataInfo list(QgPayBusiness qgPayBusiness) {
        startPage();
        List<QgPayBusiness> list = qgPayBusinessService.selectQgPayBusinessList(qgPayBusiness);
        return getDataTable(list);
    }

    /**
     * 导出QGPay业务列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:business:export')")
    @Log(title = "QGPay业务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QgPayBusiness qgPayBusiness) {
        List<QgPayBusiness> list = qgPayBusinessService.selectQgPayBusinessList(qgPayBusiness);
        ExcelUtil<QgPayBusiness> util = new ExcelUtil<QgPayBusiness>(QgPayBusiness.class);
        util.exportExcel(response, list, "QGPay业务数据");
    }

    /**
     * 获取QGPay业务详细信息
     */
    @PreAuthorize("@ss.hasPermi('qgPay:business:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qgPayBusinessService.selectQgPayBusinessById(id));
    }

    /**
     * 新增QGPay业务
     */
    @PreAuthorize("@ss.hasPermi('qgPay:business:add')")
    @Log(title = "QGPay业务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QgPayBusiness qgPayBusiness) {
        return toAjax(qgPayBusinessService.insertQgPayBusiness(qgPayBusiness));
    }

    /**
     * 修改QGPay业务
     */
    @PreAuthorize("@ss.hasPermi('qgPay:business:edit')")
    @Log(title = "QGPay业务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QgPayBusiness qgPayBusiness) {
        return toAjax(qgPayBusinessService.updateQgPayBusiness(qgPayBusiness));
    }

    /**
     * 删除QGPay业务
     */
    @PreAuthorize("@ss.hasPermi('qgPay:business:remove')")
    @Log(title = "QGPay业务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qgPayBusinessService.deleteQgPayBusinessByIds(ids));
    }

    /**
     * 选项
     *
     * @param condition 查询条件
     * @return {@link TableDataInfo}
     * @since 2023/3/16 21:50
     */
    @GetMapping("/option")
    public TableDataInfo option(QgPayBusiness condition) {
        List<QgPayBusiness> list = qgPayBusinessService.optionList(condition);
        return getDataTable(list);
    }

    /**
     * h5查询集合
     *
     * @param condition 查询条件
     * @return {@link TableDataInfo}
     * @since 2023/3/16 21:50
     */
    @GetMapping("/app/list")
    public TableDataInfo appList(QgPayBusiness condition) {
        List<QgPayBusiness> list = qgPayBusinessService.optionList(condition);
        return getDataTable(list);
    }
}
